package com.bjtu.literatureclient.api.vo.response;

import com.bjtu.literatureclient.api.Constans;
import com.bjtu.literatureclient.domain.user.UserIndexNoTable;
import com.bjtu.literatureclient.util.LocalDateTimeAndStringUtil;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;

import java.time.LocalDateTime;

/**
 * @author caiyuli
 * @date 2020/4/25 12:16 下午
 */
public class UserSyncRecord {

    private String userNo;

    private String indexNo;

    private String item;

    private String indexCode;

    private String indexCodeValue;

    private int status;

    private String statusValue;

    private String stamp;

    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime stampTime;


    public static UserSyncRecord of(UserIndexNoTable userIndexNoTable){
        UserSyncRecord record = new UserSyncRecord();
        record.setIndexNo(userIndexNoTable.getIndexNo());
        record.setUserNo(userIndexNoTable.getUserNo());

        record.setItem(userIndexNoTable.getItem());

        record.setIndexCode(userIndexNoTable.getIndexCode());
        record.setIndexCodeValue(Constans.indexCodeValueMapper.getOrDefault(userIndexNoTable.getIndexCode(),"-"));

        record.setStatus(userIndexNoTable.getStatus());
        record.setStatusValue(Constans.operationMapper.getOrDefault(userIndexNoTable.getStatus(),"-"));

        record.setStamp(userIndexNoTable.getStamp());
        record.setStampTime(LocalDateTimeAndStringUtil.stringToLocalDateTime(userIndexNoTable.getStamp()));

        return record;
    }


    public String getUserNo() {
        return userNo;
    }

    public void setUserNo(String userNo) {
        this.userNo = userNo;
    }

    public String getIndexNo() {
        return indexNo;
    }

    public void setIndexNo(String indexNo) {
        this.indexNo = indexNo;
    }

    public String getItem() {
        return item;
    }

    public void setItem(String item) {
        this.item = item;
    }

    public String getIndexCode() {
        return indexCode;
    }

    public void setIndexCode(String indexCode) {
        this.indexCode = indexCode;
    }

    public String getIndexCodeValue() {
        return indexCodeValue;
    }

    public void setIndexCodeValue(String indexCodeValue) {
        this.indexCodeValue = indexCodeValue;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getStatusValue() {
        return statusValue;
    }

    public void setStatusValue(String statusValue) {
        this.statusValue = statusValue;
    }

    public String getStamp() {
        return stamp;
    }

    public void setStamp(String stamp) {
        this.stamp = stamp;
    }

    public LocalDateTime getStampTime() {
        return stampTime;
    }

    public void setStampTime(LocalDateTime stampTime) {
        this.stampTime = stampTime;
    }
}
